package com.zxhhyj.music.ui

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Add
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.zxhhyj.music.logic.database.AppDatabase
import com.zxhhyj.music.logic.table.MediaSource
import com.zxhhyj.music.logic.table.WebdavSourceTable
import com.zxhhyj.ui.view.AppCenterTopBar
import com.zxhhyj.ui.view.AppIconButton
import com.zxhhyj.ui.view.AppScaffold

@Composable
fun Source() {
    AppScaffold(
        modifier = Modifier.fillMaxSize(),
        topBar = {
            AppCenterTopBar(
                actions = {
                    AppIconButton(
                        onClick = {
                            AppDatabase.beginTransaction {
                                insert(
                                    WebdavSourceTable,
                                    MediaSource.Webdav(username = "username", password = "password")
                                )
                            }
                        }) {
                        Icon(imageVector = Icons.Rounded.Add, contentDescription = null)
                    }
                }) {
                Text("Source")
            }
        }) {
        LazyColumn(modifier = Modifier.fillMaxSize(), contentPadding = it) {
            items(AppDatabase.form(WebdavSourceTable).select().asKotlinSequence().toList()) {
                Text(it[WebdavSourceTable.username])
            }
        }
    }
}